package sns.action;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.Relation;
import sns.bean.User;
import sns.dao.RelationDao;
import sns.dao.UserDao;
import sns.service.ImpressionService;
import sns.service.RelationService;
import sns.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class RemoveFanAction extends ActionSupport {

	// injection
	private UserDao userDao;
	private UserService userService;
	private RelationService relationService;
	private RelationDao relationDao;
	private ImpressionService impressionService;
	// pass in
	private Long visitId;

	// return

	@Transactional
	public String execute() {

		if (visitId == null) {
			System.out.println("No visit Id");
			return ActionSupport.INPUT;
		}
		User visitUser = userDao.findUserById(visitId);
		User currentUser = userService.getCurrentUser();
		Relation relation = relationService.getRelation(visitUser,currentUser );
		if (relation == null) {
			System.out.println("They are not related");
			return ActionSupport.ERROR;
		}
		
		impressionService.deleteImpressionByRelation(relation);
		relationDao.delete(relation);

		return ActionSupport.SUCCESS;
	}

	public Long getVisitId() {
		return visitId;
	}

	public void setVisitId(Long visitId) {
		this.visitId = visitId;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setRelationService(RelationService relationService) {
		this.relationService = relationService;
	}

	public void setRelationDao(RelationDao relationDao) {
		this.relationDao = relationDao;
	}

	public void setImpressionService(ImpressionService impressionService) {
		this.impressionService = impressionService;
	}
	
}
